//
//  CYUserLBL.m
//  CaiYun
//
//  Created by 今日信息科技 on 2017/6/29.
//  Copyright © 2017年 今日信息科技. All rights reserved.
//

#import "CYUserLBL.h"
@interface CYUserLBL ()

@property (nonatomic, strong) CYLabel *titleLBL;
@property (nonatomic, strong) CYLabel *moneyLBL;
@property (nonatomic, strong) CYView *backview;
@property (nonatomic, strong) CYView *leftLine;
@property (nonatomic, strong) CYView *rightLine;
@property (nonatomic, copy) NSString *title;
@end
@implementation CYUserLBL
- (instancetype)initWithTitle:(NSString *)title{
    self = [super init];
    if (self) {
        
        self.title = title;
        self.backview.alpha = 0.2;
        self.leftLine.hidden = self.rightLine.hidden =  ([title isEqualToString:@"提款金额"])?NO:YES;
        self.moneyLBL.hidden = NO;
    }
    return self;
}

- (void)setTitle:(NSString *)title{
    if (_title != title) {
        _title = title;
        self.titleLBL.text = title;
    }
}

- (void)setMoney:(float )money{
    if (_money != money){
        _money = money;
        self.moneyLBL.text = [NSString stringWithFormat:@"%.2f",money];
        [self updateMoneyBounds];
    }

}


- (CYLabel *)titleLBL{
    if (!_titleLBL) {
        _titleLBL = [[CYLabel alloc]initWithText:_title size:AL(PT(22)) textcolor:[UIColor whiteColor]];
        [self addSubview:_titleLBL];
        
        [_titleLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.mas_centerY).with.offset(AL(PT(6)));
            make.centerX.equalTo(self);
            make.size.mas_equalTo(_titleLBL.bounds.size);
        }];
    }
    return _titleLBL;
}

- (CYLabel *)moneyLBL{
     if (!_moneyLBL) {
        _moneyLBL = [[CYLabel alloc]initWithText:@"0.00" size:AL(PT(22)) weight:UIFontWeightBold];//
        _moneyLBL.textColor = [UIColor whiteColor];
        [self addSubview:_moneyLBL];
        
        [_moneyLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(_titleLBL.mas_top).with.offset(- AL(PT(12)));
            make.centerX.equalTo(_titleLBL);
            make.size.mas_equalTo(_moneyLBL.bounds.size);
        }];
    }
    return _moneyLBL;
}

- (CYView *)backview{
    if (!_backview) {
        _backview  = [[CYView alloc]init];
        _backview.backgroundColor = [UIColor whiteColor];
        [self addSubview:_backview];
        
        [_backview mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_offset(UIEdgeInsetsZero);
        }];
    }
    
    return _backview;
}

- (CYView *)leftLine{
    if (!_leftLine) {
        _leftLine = [[CYView alloc]initWithColor:[UIColor whiteColor]];
        [self addSubview:_leftLine];
        
        [_leftLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).with.offset(0);
            make.centerY.equalTo(self);
            make.size.mas_equalTo(CGSizeMake(0.5, AL(PT(100 / 2.0))));
        }];
        
    }
    return _leftLine;
}

- (CYView *)rightLine{
    if (!_rightLine) {
        _rightLine = [[CYView alloc]initWithColor:[UIColor whiteColor]];
        [self addSubview:_rightLine];
        
        [_rightLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.mas_right).with.offset(0);
            make.centerY.equalTo(self);
            make.size.mas_equalTo(CGSizeMake(0.5, AL(PT(100 / 2.0))));
        }];
        
    }
    return _rightLine;
}

//更新金额bounds
- (void)updateMoneyBounds{
    
    [_moneyLBL mas_updateConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_titleLBL);
        make.size.mas_equalTo(_moneyLBL.bounds.size);
    }];
    
}

//根据宽度，自适应金额数字的font
//- (void)autoMoneyFont:(CGFloat )size{
//    
//    CGFloat width = ceil([_money sizeWithAttributes:@{NSFontAttributeName :[UIFont systemFontOfSize:size weight:UIFontWeightBold]}].width);
//    
//    if (width >= SCREEN_WIDTH / 3.0 - AL(20))
//        [self autoMoneyFont:size - 1];
//    else
//        _moneyLBL.font = [UIFont systemFontOfSize:size weight:UIFontWeightBold];
//    [_moneyLBL sizeToFit];
//}
/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end


@interface CYPassWordLBL()
@property (nonatomic, strong) CYLabel *placeholderLBL;
@property (nonatomic, copy) NSString *placeholder;
@property (nonatomic, strong) CYButton *downBtn;
@property (nonatomic, strong) CYView *line;
@property (nonatomic, strong) CYImageView *leftView;

@end

@implementation CYPassWordLBL
- (instancetype)initWithPlaceholder:(NSString *)placeholder{
    self = [super init];
    if (self) {
        _placeholder = placeholder;
        self.userInteractionEnabled = YES;
        self.line.hidden = self.placeholderLBL.hidden = self.downBtn.hidden = NO;
        
    }
    
    
    return self;
}
- (CYLabel *)placeholderLBL{
    if (!_placeholderLBL) {
        _placeholderLBL = [[CYLabel alloc]initWithText:_placeholder size:AL(PT(28)) textcolor:RGBA(207, 207, 212, 1)];
        [self addSubview:_placeholderLBL];
        
        WS(self)
        [_placeholderLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf).with.offset(0);
            make.bottom.equalTo(weakSelf.mas_bottom).with.offset(-3);
            make.size.mas_equalTo(_placeholderLBL.bounds.size);
        }];
    }
    
    return _placeholderLBL;
}

- (CYButton *)downBtn{
    
    if (!_downBtn) {
        _downBtn = [[CYButton alloc]initWithImage:@"xiala" cornerRadius:0.0];
        [_downBtn addTarget:self action:@selector(actionFordownBtn) forControlEvents:UIControlEventTouchUpInside];
        _downBtn.imageEdgeInsets = UIEdgeInsetsMake(0.0, 0.0, 0.0, -((AL(40 ) - _downBtn.imageView.bounds.size.width) / 2.0 - AL(5)));
        [self addSubview:_downBtn];
        
        WS(self)
        [_downBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(weakSelf);
            make.right.equalTo(weakSelf.mas_right).with.offset(0);
            make.size.mas_equalTo(CGSizeMake(AL(40), AL(44)));
        }];
    }
    return _downBtn;
}

- (CYView *)line{
    if (!_line) {
        _line = [[CYView alloc]initWithColor:[UIColor lightGrayColor]];
        [self addSubview:_line];
        
        WS(self)
        [_line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf).with.offset(0);
            make.bottom.equalTo(weakSelf.mas_bottom).with.offset(0);
            make.right.equalTo(weakSelf.mas_right).with.offset(0);
            make.height.mas_equalTo(0.5);
        }];
    }
    return _line;
}


- (void)actionFordownBtn{
    _placeholderLBL.textColor = [UIColor blackColor];
    _placeholderLBL.text = @"这是一个测试的问题";
    [self.CYdelegate actionForDrapDown];
}
@end
